<?php
require_once('../lib/standard.php');
require_once('../lib/notes.php');

global $pineza;
$pineza = new Globals(FALSE);

if ((!perastike('login')) || (!$_REQUEST['login'])) print_error('no login name passed');
else $login = $_REQUEST['login'];
if ($login != $pineza->login) print_error('access denied!');

$note = FALSE;
if (perastike('note')) {
	$query = "SELECT * FROM `note` WHERE `key` = " .
		escape($_REQUEST['note']) . " LIMIT 1";
	$result = mysqli_query($pineza->db, $query);
	if (!$result) print_error('SQL failed');

	while ($note = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
		mysqli_free_result($result);
		break;
	}
	if (!$note) print_error('note not found: ' . $_REQUEST['note']);

	if ($note['user'] != $pineza->login) print_error('access denied');
	$board = $note['board'];
}
elseif (perastike('board')) {
	$board = $_REQUEST['board'];
}
else {
	print_error('board undefined');
}

forma_note($board, $note);
$pineza->close_database();
print AJAX_SEP;

function print_error($msg) {
	global $pineza;
	$pineza->close_database();
	print 'ERROR@' . $msg . AJAX_SEP;
	die(1);
}

?>
